package com.tensquare.articlecrawler.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.netflix.discovery.converters.Auto;
import com.tensquare.articlecrawler.pipeline.ArticleDBPipeline;
import com.tensquare.articlecrawler.processor.ArticlePageProcessor;

import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.scheduler.Scheduler;

/**
 * 任务类
 * @author Johnny.Chen
 *
 */
@Component
public class ArticleTask {
	
	@Autowired
	private ArticlePageProcessor articlePageProcessor;
	
	@Autowired
	private ArticleDBPipeline articleDBPipeline;
	
	@Autowired
	private Scheduler scheduler;
	
	@Value("${tensquare.webmagic.urls}")
	private String urls;
	
	@Scheduled(cron="${tensquare.webmagic.time1}")
	public void task1() {
		System.out.println("启动了......");
		Spider.create(articlePageProcessor)
			.addUrl(urls) //添加入口页面
			.addPipeline(articleDBPipeline) //远程调用的pipeline
			.setScheduler(scheduler) //用于url去重
			.start();
	}

}
